/**
 * Copyright (C) 2011 Computer Science Department, Loei Rajabhat University
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package th.ac.lru.cs.ktd.frame;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.EditorKit;
import javax.swing.JEditorPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;

public class InformationSmallFrame extends JDialog {
	
	private static final long serialVersionUID = -7325741385138708947L;

	private static InformationSmallFrame mInformationInstance;
	private final String HTML_TYPE = "text/html";
	
	@SuppressWarnings("unused")
	private DictionaryMainFrame mParentFrame;	

	private JPanel mContentPane;

	private JButton mButtonCloseWindow;
	private JEditorPane mEditorPane;
	private JScrollPane mScrollPane;
	
	public static InformationSmallFrame newInstance(DictionaryMainFrame parent, String htmlContent) {
		mInformationInstance = new InformationSmallFrame(htmlContent);
		mInformationInstance.mParentFrame = parent;
		return mInformationInstance;
	}
	
	/**
	 * Create the frame.
	 */
	public InformationSmallFrame(String htmlContent) {
		setTitle("Korean Thai Dictionary - Information");
		setBounds(100, 100, 450, 300);
		mContentPane = new JPanel();
		mContentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		setContentPane(mContentPane);
		mContentPane.setLayout(null);
		
		mEditorPane = new JEditorPane();
		mEditorPane.setBounds(0, 0, 442, 248);
		mEditorPane.setEditable(false);
		mContentPane.add(mEditorPane);

		EditorKit editKit = mEditorPane.getEditorKitForContentType(HTML_TYPE);
		mEditorPane.setEditorKit(editKit);
		mEditorPane.setText(htmlContent);		
		mEditorPane.setCaretPosition(0);
		mContentPane.add(mEditorPane);		
		
		mButtonCloseWindow = new JButton("ปิดหน้าต่าง");
		mButtonCloseWindow.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				mInformationInstance = null;
			}
		});
		mButtonCloseWindow.setBounds(351, 249, 91, 18);
		mContentPane.add(mButtonCloseWindow);
		
		mScrollPane = new JScrollPane();
		mScrollPane.setBounds(0, 0, 442, 248);
		mScrollPane.setViewportView(mEditorPane);
		mContentPane.add(mScrollPane);
	}
}
